<!--tab cho app-->

<link rel="stylesheet" href="/css/jquery-ui.css" />
<script src="/js/jquery-tab-app.js"></script>
<script src="/js/jquery-ui.js"></script>
<script>
  $(function() {
    $( "#tabs" ).tabs();
  });
  </script>

<?php
    $modelR = new RemoveCircumflex();
    $modelPT = new ParentTypeModel();
    $link = $this->link;
    $url = $this->url;
	$channel= $this->channel;
    
    //Trang xem
    if(isset($link['id'])):
    if(isset($this->film)) $film = $this->film;
    
    $index_type = explode('|',$film[0]['type']);
    $parent_type = $modelPT->getTypeById($index_type[0]);
    $type = explode('|',$film[0]['name_types']);
    for($i = 0;$i < count($type); $i++){
            $type[$i] = explode('-',$type[$i]);
    };
?>

				<div id="video">
					<center><h2 class="video-title"><?php //echo $film[0]['title_vi']?></h2></center>
				   
					 <?php if($film[0]['type_data_ep'] == 0){?>
					 
					<script language="javascript">
							$(document).ready(function(){
								var width = $(window).width()*.9;
								if(width>320){
								var height = width*0.7
				
								}else{
								var height = width*0.6;
								}
								
								var width_max = 640;
								var height_max = 360;
								if(width > width_max){
									$('#player').css('width', width_max);
									$('#player').css('height', height_max);
								}else{
									$('#player').css('width', width);
									$('#player').css('height', height);
								}
								
								$(window).resize(function() {
									width = $(window).width()*0.9;
									height = width*0.6;
									if(width > width_max){
									$('#player').css('width', width_max);
									$('#player').css('height', height_max);
									}else{
										$('#player').css('width', width);
										$('#player').css('height', height);
									}
								})
							})
					</script>
				    
					<!--<div class="container_player" style ="margin-top:30px;z-index:999;display:block;position: fixed;clear:both;><center><div class="vendor"><div id="player"></div></div></center></div>
					-->
					<script>
					var hash = window.location.hash;//Lay thong so #ep
					if(hash != ''){
							hash = hash.split('#ep');
							hash = hash[1].split('-');
							hash = hash[0];
					}else hash = 1;
					
					var tag = document.createElement('script');
					tag.src = "//www.youtube.com/iframe_api";
					var firstScriptTag = document.getElementsByTagName('script')[0];
					firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
					var player;
					var playlist = [<?php echo $film[0]['id_eps'];?>];
					function onYouTubePlayerAPIReady() {
						 player = new YT.Player('player', {
						  //location: 'MOBILE',
						  //height: '390',
						  //width: '100%',
						  playerVars: {
							'autoplay': 0,
							'controls': 1,
						  },
						  events: {
							'onReady': onPlayerReady,
							'onStateChange': onPlayerStateChange,
							//'onPlaybackQualityChange': testfunc(),
						  }
						});
					}
					function onPlayerReady(event) { 
						event.target.cuePlaylist(playlist,hash-1); 
					}
					  //var done = false;
					var flag_start = 0;
					var flag_play  = 0;
					var text = "";
					var tap = hash-2;
					var href = window.location.href;
					tmp_href = href.split('#ep');
					//if(tmp_href[1] == null) tmp_href = href.split('.html');
					href = tmp_href[0];
					function onPlayerStateChange(event) {
						if(event.data == -1) flag_start = 1;
						if(event.data == 1) flag_play = 1;
						
						if(flag_start == 1 && flag_play == 1){
							tap++;
							text = $('#ep-'+tap).text();//lay tieu de cua tap phim
							text = locdau(text);//o dau tieu de

							$('.episode').removeClass('playing');
							$('.ep-'+tap).addClass('playing');
							window.location.replace(href+'#ep'+tap+'-'+text);//day ep len url
							
							flag_start = 0;
							flag_play  = 0;
						}
					}
					function stopVideo() {
						player.stopVideo();
					}
					function playAt(ep){
						player.playVideoAt(ep);
						tap = ep;
					}
					function playNext()
					{
						var number_eps = $(".episode").length;
						hash = window.location.hash;//Lay thong so #ep
						hash = hash.split('#ep');
						hash = hash[1].split('-');
						hash = parseInt(hash[0]);
						hash = hash+1;
						if(hash > 0){
							player.playVideoAt(hash-1);
							tap = hash-1;        
						}else{
							alert("Không còn tập nào phía trước.");
						}
					}
					function playPrev()
					{
						hash = window.location.hash;//Lay thong so #ep
						hash = hash.split('#ep');
						hash = hash[1].split('-');
						hash = parseInt(hash[0]);
						hash = hash-1;
						if(hash > 0){
							player.playVideoAt(hash-1);
							tap = hash-1;        
						}else{
							alert("Không còn tập nào phía trước.");
						}
					}
					function locdau(str) {
					  str= str.toLowerCase();
					  str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
					  str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
					  str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
					  str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
					  str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
					  str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
					  str= str.replace(/đ/g,"d");
					  str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-");
						/* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
					  str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1-
					  str= str.replace(/^\-+|\-+$/g,"");
						//cắt bỏ ký tự - ở đầu và cuối chuỗi
					  return str;
					 } 
					</script>
					</div>

    <?php }else{?>
    <div id="cover_player_flash">
        <div id="player"></div>
    </div>
        <script>
            var text = "";
            var hash = window.location.hash;//Lay thong so #ep
            var url = window.location.pathname;
            var id  = <?php echo $link['id']?>;
            var strURL = "/index/hash";
            var href = window.location.toString();
            tmp_href = href.split('#ep');
            href = tmp_href[0];
            if(hash != ''){
                    hash = hash.split('#ep');
                    hash = hash[1].split('-');
                    hash = hash[0];
            }else{
                hash = 1;
            } 
            window.onload = function(){
               
                $.ajax({
        			url:strURL,
        			type:"POST",
        			data:{'hash':hash,'id' :id},
        			success:function(msg){	
            		      $("#player").html(msg);					
        			}
    			});
                
                $('.episode').removeClass('playing');
                $('.ep-'+hash).addClass('playing');
                
                text = $('#ep-'+hash).text();//lay tieu de cua tap phim
                text = locdau(text);//o dau tieu de
                window.location.replace(href+'#ep'+hash+'-'+text);//day ep len url   
            }
            
            function playAt(ep){
                $.ajax({
        			url:strURL,
        			type:"POST",
        			data:{'hash':ep+1,'id' :id},
        			success:function(msg){						
            		      $("#player").html(msg);					
        			}
    			});
                $('.episode').removeClass('playing');
                $('.ep-'+(ep+1)).addClass('playing');
            }
            function playPrev(){
                hash = window.location.hash;//Lay thong so #ep
                hash = hash.split('#ep');
                hash = hash[1].split('-');
                hash = parseInt(hash[0]);
                hash = hash-1;
                if(hash > 0){
                    $.ajax({
            			url:strURL,
            			type:"POST",
            			data:{'hash':hash,'id' :id},
            			success:function(msg){						
                		      $("#player").html(msg);					
            			}
        			});
                    text = $('#ep-'+hash).text();//lay tieu de cua tap phim
                    text = locdau(text);//o dau tieu de
                    
                    $('.episode').removeClass('playing');
                    $('.ep-'+hash).addClass('playing');
                    window.location.replace(href+'#ep'+hash+'-'+text);//day ep len url
                }else{
                    alert("Không còn tập nào phía trước.");
                }
            }
            function playNext(){
                var number_eps = $(".episode").length;
                hash = window.location.hash;//Lay thong so #ep
                hash = hash.split('#ep');
                hash = hash[1].split('-');
                hash = parseInt(hash[0]);
                hash = hash+1;
                if(hash <= number_eps){
                    $.ajax({
            			url:strURL,
            			type:"POST",
            			data:{'hash':hash,'id' :id},
            			success:function(msg){						
                		      $("#player").html(msg);					
            			}
        			});
                    text = $('#ep-'+hash).text();//lay tieu de cua tap phim
                    
                    text = locdau(text);//o dau tieu de
                    
                    $('.episode').removeClass('playing');
                    $('.ep-'+hash).addClass('playing');
                    window.location.replace(href+'#ep'+hash+'-'+text);//day ep len url
                }else{
                    alert("Không còn tập nào phía sau.");
                }
            }
            
            function locdau(str) {
              str= str.toLowerCase();
              str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
              str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
              str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
              str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
              str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
              str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
              str= str.replace(/đ/g,"d");
              str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-");
                /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
              str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1-
              str= str.replace(/^\-+|\-+$/g,"");
                //cắt bỏ ký tự - ở đầu và cuối chuỗi
              return str;
             } 
        </script>
    <?php }?>
			<div id="btn-tools" style ="margin-top:-20px;z-index:999;">
										<!--play video-->
										<div class="container_player" ><center><div class="vendor"><div id="player"></div></div></center></div>
										<!--end play video-->	
										<!--menu play-->				
											<div>
												
												<div id="btn-controls">
													<a class="btn-control prev-btn" title="Tập trước" onclick="playPrev()">&nbsp;</a>
													
													<a class="btn-control next-btn" title="Tập tiếp" onclick="playNext()">&nbsp;</a>
													<a href="#"><?php echo substr($film[0]['title_vi'],0,30).".. ";?></a>
												</div>
												 <p class="video-info" style="padding-right:30px;">
												
												 <?php echo"| " .$film[0]['hits']." view";?>
												</p>
											</div>
										<!--end menu play-->
									<!--Tab list,thong tin, video khac-->										
									<div id="tabs">
										<ul>
											<li><a href="#tabs-1">List Album</a></li>
											<li><a href="#tabs-2">Thông Tin</a></li>
											<li><a href="#tabs-3">Video Khác</a></li>
										  </ul>
										  <div id="tabs-1">
										  <?php
												$id_eps = stripslashes($film[0]['id_eps']);
											     $id_eps = explode(',',$id_eps);
												 echo "Album có : ".count($id_eps)." bài bát";
												 ?>
												<div id="list-eps" style="clear: both;margin-top:0px;">
												 
														<ul>
														<?php
															$name_eps = stripslashes($film[0]['des_eps']);
															if($name_eps != "#|#" && $name_eps != ""){
																$name_eps  = explode('#|#',$name_eps);
																for($i = 0;$i<count($name_eps);$i++){
																	echo "<li class='episode ep-".($i+1)."'><span>".($i+1)."</span><a id='ep-".($i+1)."' href='#ep".($i+1)."-".$modelR->rewrite($name_eps[$i])."' onclick='playAt(".$i.")'>".$name_eps[$i]."</a><div class='clear'></div></li>";
																}
															}else{
																$id_eps = stripslashes($film[0]['id_eps']);
																$id_eps = explode(',',$id_eps);
																for($i = 0;$i<count($id_eps);$i++){
																	echo "<li class='episode ep-".($i+1)."'><span>".($i+1)."</span><a id='ep-".($i+1)."' href='#ep".($i+1)."-tap".($i+1)."' onclick='playAt(".$i.")'>Tập ".($i+1)."</a><div class='clear'></div></li>";
																}
															}
														 ?>
														 </ul>
														 
												</div>
												<div>
												
												</div>
										  
										  </div>
										  <div id="tabs-2">
											<div class="box-info-block">
											
											<head> <a><img property="og:image:secure_url" width="80px" height="60px" src="<?php echo $film[0]['thumb']?>"  rel="image_src" alt ="<?php echo $film[0]['title_vi']?>"/></a></head>
											
											<div class="row2" expand="row2" id="_info" style="padding-left:10px;"><?php echo $film[0]['description']?></div>
										     
											</div>
											<div style="border-top:1px solid #ccc; padding:3px;font-weight:bold;  ">
													Thể loại:<?php for($i=1;$i<count($index_type);$i++){?>
												 <?php if($i != 1){?>
												 ,
												 <?php }?>
												 <?php for($j = 0;$j < count($type);$j++){if($type[$j][0] == $index_type[$i]){?>
												 <a style="color:#f00;" href="/app/<?php echo $modelR->rewrite($parent_type[0]['name']);?>/category/1-<?php echo $index_type[0];?>-<?php echo $type[$j][0]?>-<?php echo $modelR->rewrite($type[$j][1]); ?>.html?channel=<?php echo $channel?>"><?php echo $type[$j][1];};?></a>
												 <?php }?>
												 <?php }?>
												
												<?php if($film[0]['source'] != null && $film[0]['source'] != "") echo "| Nguồn: ".$film[0]['source']?>
											</div>
										   <div style="clear:both;"></div>
										  </div>
										  <div id="tabs-3">
										  <?php 
										  $relatedvideo=$this->relatedvideo;
										 
										  ?>
										  <div id="list-eps2">
										<ul class="list_video">
										<?php
											foreach( $relatedvideo as $item):
										 ?>
										 <li><a href="/app/<?php echo $modelR->rewrite($item['name']);?>/detail/<?php echo $item['id']?>-<?php echo $modelR->rewrite($item['title_vi']);?>.html?channel=<?php echo $channel?>">
											<img src="<?php echo $item['thumb']?>"/>
											<span>
												<h3 class="title_video"><?php echo $item['title_vi']?></h3>
												<p><?php echo $item['national']?> | Lượt xem: <?php echo $item['hits']?></p>
											</span>
											<div class="clear"></div>
										 </a></li>
										 <?php
											endforeach;
										  ?>
									       </ul>
										   </div>
																		  </div>
																		</div>
		
		</div>
</div>
   
	
    
<?php
    //Trang thu muc cha
    elseif(isset($link['cate']) && !isset($link['type'])):
        $listFilm = $this->listFilm;
        $category1 = $listFilm[0]['type'];
        $category1 = explode('|',$category1);
        $category1 = $category1[0];
        $name_cate = explode('.html',$_SERVER['REQUEST_URI']);
        $name_cate = $name_cate[0];
        $name_cate = explode('-',$name_cate,3);
        $name_cate = $name_cate[2];
    
        $name = $listFilm[0]['name_types'];
        $name = explode('|',$name);
        for($i = 0;$i < count($name); $i++){
                $name[$i] = explode('-',$name[$i]);
        };
        $num_type = count($name);
        for($i=0; $i< $num_type; $i++):
 ?>
 <div>
 
	
 </div>
    <div class="box_top box_type">
            <h2 class="label_top"><?php echo $name[$i][1]?> mới nhất</h2>
            <ul class="list_video">
            <?php if($this->listFilm != '' && $this->listFilm  != null){
                $dem = 0;
                foreach($this->listFilm  as $item){
                if($dem == 6) break;
                $type = explode('|',$item['type']);
                $flag = true;
                for($m = 1; $m < count($type); $m++){
                    if($type[$m] == $name[$i][0] && $type[$m] != ''){
                        $flag = true;
                        break;
                    }else $flag = false;
                };
                if($flag == true){
            ?>
            <li><a href="/app/<?php echo $modelR->rewrite($item['name']);?>/detail/<?php echo $item['id']?>-<?php echo $modelR->rewrite($item['title_vi']);?>.html">
                <img src="<?php echo $item['thumb']?>"/>
                <span>
                    <h3 class="title_video"><?php echo $item['title_vi']?></h3>
                    <p><?php echo $item['national']?> | Lượt xem: <?php echo $item['hits']?></p>
                </span>
                <div class="clear"></div>
            </a>
            </li>
            <?php $dem++;}}}?>     
        </ul>
        <a class='read_more' href="/app/<?php echo $name_cate?>/category/1-<?php echo $category1?>-<?php echo $name[$i][0]?>-<?php echo $modelR->rewrite($name[$i][1])?>.html">Xem tiếp &raquo;</a>
    </div>
 <?php 
        endfor;
    //Trang the loai con
    elseif(isset($link['cate']) && isset($link['type'])):
 ?>
 
 <!--quang cao-->
	<!--
   <center><div id="sunnet_widget_44" style="display: none;padding:10px;">
    
    <script type="text/javascript">var is_load_sunnet_lib = is_load_sunnet_lib || 1;if(is_load_sunnet_lib == 1) {is_load_sunnet_lib = 2;if(typeof(jQuery)=='undefined') {document.write(unescape("%3Cscript src='http://amobi.vn/js/default/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E"));}document.write(unescape("%3Cscript src='http://amobi.vn/js/default/sunnet.js' type='text/javascript'%3E%3C/script%3E"));}</script>
    <script type="text/javascript" src="http://amobi.vn/index/widget?widget_id=44"></script>    </center>    
      
	</div></center>-->
	
	<!--end quang cao-->
 <div class="box_top" style="clear:both;">
 <h2 class="label_top"><?php echo $this->label_top;?></h2>
 <ul class="list_video">
         <?php $paginationControl = $this->paginationControl($this->paginator, 'Sliding', '/index/paginator.phtml') ?>
         <?php if (count($this->paginator)) : ?>
         <?php
                $dem = 1;
                foreach($this->paginator  as $item){
                $type = explode('|',$item['type']);
                $name_types = explode('|',$item['name_types']);
                for($i = 0;$i < count($name_types); $i++){
                        $name_types[$i] = explode('-',$name_types[$i]);
                };
            ?>
            <li><a href="/app/<?php echo $modelR->rewrite($item['name']);?>/detail/<?php echo $item['id']?>-<?php echo $modelR->rewrite($item['title_vi']);?>.html">
            <img src="<?php echo $item['thumb']?>"/>
            <span>
                <h3 class="title_video"><?php echo $item['title_vi']?></h3>
                <p><?php echo $item['national']?> | Lượt xem: <?php echo $item['hits']?></p>
            </span>
            <div class="clear"></div>
            </a></li>
            <?php $dem++;}?>   
            <?php endif;?>      
        </ul>
 </div>
 <div class="pagi-control" >
 <?php echo $paginationControl; ?>
 </div>
 <?php 
 
    //Trang chu
    else:
 ?>
 <div>
 <div class="swiper-container">
		<div class="swiper-wrapper">
		<?php
            foreach($this->newvideo as $item):
         ?>
			<div class="swiper-slide" style="background-image:url(<?php echo $item['thumb']?>);" ></div>
	
			
		 <?php
            endforeach;
          ?>	
		</div>
	</div>
   <script src="/templates/mobile/js/idangerous.swiper-2.0.min.js"></script>
	<script src="/templates/mobile/js/idangerous.swiper.3dflow-2.0.js"></script>
	<script>
	var mySwiper = new Swiper('.swiper-container',{
		slidesPerView:3,
		loop:true,
		//Enable 3D Flow
		tdFlow: {
			rotate : 30,
			stretch :10,
			depth: 150,
			modifier : 1,
			shadows:true
		}
	})
	</script>
 
 
 

 </div>
 <?php 
    //Trang chu
    endif;
	
 ?>